{% extends "base/base.html" %}
{% load staticfiles %}

{% block customizedCSS %}
    <!-- this page specific styles -->
    <link rel="stylesheet" href="/static/css/compiled/user-list.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="/static/css/kkpager_blue.css">

    <style type="text/css">
    *{font-family:'Microsoft YaHei';}
    .name{display: block;font-weight: 600;font-size: 14px;
        margin:15px 0 0 0;}
        #tb a{text-decoration: underline;}
    </style>
{% endblock %}

{% block content %}
<div class="container-fluid">
            <div id="pad-wrapper">
<!-- orders table -->
                <div id="pad-wrapper" class="users-list">
                    <div class="row-fluid header">
                        <div class="span12">
                            <h3>销售订单列表</h3>
                        </div>
                        </div>
                    </div>

                    <div class="row-fluid filter-block" style="margin-bottom: 20px">
                        <div class="pull-right">
                            <div class="btn-group pull-right">
                                <button class="glow left ">所有</button>
                                <button class="glow middle large">未完成</button>
                                <button class="glow right large">已完成</button>
                            </div>
                            <input type="text" class="search order-search" placeholder="Search for an order.." style="margin-right: 30px;" />
                        </div>
                    </div>
                    <div class="row-fluid">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th class="span2">
                                        订单号
                                    </th>
                                    <th class="span2">
                                        日期
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        客户
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        状态
                                    </th>
                                    <th class="span2">
                                        <span class="line"></span>
                                        商品数量
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        总价
                                    </th>
                                    <th class="span2">
                                        <span class="line"></span>
                                        操作/查看
                                    </th>
                                </tr>
                            </thead>
                            <tbody id="tb">
                                <!-- row -->
                                {% for so in list%}
                                <tr>
                                    <td>
                                        <a>#{{ so.so_num }}</a>
                                    </td>
                                    <td>
                                        {{so.so_creattime | date:"Y年m月j日" }}
                                    </td>
                                    <td>
                                        <a>{{so.so_cust.name}}</a>
                                    </td>
                                    <td>
                                        {% if so.so_state == 0 %}
                                            <span class="label label-info">订单已创建</span>
                                        {%else%}
                                            {% if so.so_state == 1 %}
                                                <span class="label label-danger">订单运输中</span>
                                            {%else%}
                                                {% if so.so_state == 2 %}
                                                    <span class="label label-success">已完成订单</span>
                                                {%else%}
                                                    <span class="label">订单已取消</span>
                                                {%endif%}
                                            {%endif%}
                                        {%endif%}
                                    </td>
                                    <td>
                                        {{so.get_quantity}}
                                    </td>
                                    <td>
                                        {{so.get_amount | default:"0"}}
                                    </td>
                                    <td>
                                        <a href="/so/detail/?num={{so.so_num}}">查看详情</a>
                                    </td>
                                </tr>
                                {%endfor%}
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- end orders table -->
                <div class="pagination pull-right" id="kkpager">
                </div>
            </div>
        </div>
{% endblock %}

{% block customizedJS %}
<script src="/static/js/kkpager.min.js"></script>
    <script type="text/javascript">
        function getParameter(name) {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }

        $(function(){
            var totalPage = {{totalPage}};
            var totalRecords = {{totalRecords}};
            var pageNo = getParameter('page');
            var query="{{query}}";
            var latter="";
            if(!pageNo){
                pageNo = 1;
            }
            if(query=="None"){
                latter="";
            }
            //生成分页
            //有些参数是可选的，比如lang，若不传有默认值
            kkpager.generPageHtml({
                pno : pageNo,
                //总页码
                total : totalPage,
                //总数据条数
                totalRecords : totalRecords,
                //链接前部
                hrefFormer : 'so/list/',
                //链接尾部
                hrefLatter : '?query='+latter,
                getLink : function(n){
                    return this.hrefFormer + this.hrefLatter + "&page="+n;
                }
            });
        });
    </script>
   {% endblock %}
